package export.pet
{
	import base.BaseBitmapDataClip;
	import base.BaseBitmapDataPool;
	import base.BaseBullet;
	import base.BaseHero;
	import base.BasePet;
	
	import com.dusk.util.ResUtil;
	import com.game.data.vo.PetDataVO;
	
	import export.bullet.SpecialEffectBullet;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	
	public class PetMouse1 extends BasePet
	{
		
		public function PetMouse1(bh:BaseHero, pi:PetDataVO)
		{
			super(bh, pi);
			this.horizonSpeed = 5;
			this.attackBackInfoDict["hit1"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [6, -5],
				"attackInterval" : 999,
				"power"          : 12,
				"attackKind"     : "magic"
			};
			this.attackBackInfoDict["hit2"] = {
				"hitMaxCount"    : 99,
				"attackBackSpeed": [-10, 0],
				"attackInterval" : 5,
				"power"          : 12,
				"attackKind"     : "physics"
			};
			this.attackRange = 200;
			this.attackRate = 0.7;
			this.setAction("idle");
			this.skillCD1 = [gc.frameClips * 4, gc.frameClips * 10];
		}
		
		override protected function initBBDC():void
		{
			var body:* = null;
			var bmdArray:Array = BaseBitmapDataPool.getBitmapDataArrayByName("PetMouseBmd1");
			if (bmdArray)
			{
				body = {
					"name"  : "body",
					"source": bmdArray
				};
				bbdc = new BaseBitmapDataClip([body], 200, 200, new Point(0, 0));
				bbdc.setOffsetXY(-20, -25);
				bbdc.setFrameStopCount([[2, 2, 2, 3, 2, 4], [4, 4, 4, 4], [8], [2, 2, 2, 2, 10], [2, 2, 10], [4, 4, 1, 10]]);
				bbdc.setFrameCount([6, 4, 1, 5, 3, 4]);
				bbdc.setEnterFrameCallBack(this.enterFrameFunc, this.exitFrameFunc);
				bbdc.setAddScriptWhenFrameOver(this.scriptFrameOverFunc);
				this.bodyContainer.addChild(bbdc);
				return;
			}
			throw new Error("PetMouseBmd1--BitmapData Error!");
		}
		
		override protected function initCollideArea():void
		{
			this.colipse = ResUtil.getNewObj("ObjectBaseSprite4") as Sprite;
			this.colipse.visible = false;
			this.addChild(this.colipse);
		}
		
		override public function setAction(str:String):void
		{
			super.setAction(str);
			var curPoint:Point = this.bbdc.getCurPoint();
			switch (str)
			{
				case "idle":
					if (curPoint.y != 0)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(0);
					}
					this.bbdc.setState(str);
					return;
				case "walk":
					if (curPoint.y != 1)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(1);
					}
					this.bbdc.setState(str);
					return;
				case "hurt":
					if (curPoint.y != 2)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(2);
					}
					this.bbdc.setState(str);
					return;
				case "hit1":
					if (curPoint.y != 4)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(4);
					}
					this.bbdc.setState(str);
					return;
				case "hit2":
					if (curPoint.y != 5)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(5);
					}
					this.bbdc.setState(str);
					return;
				case "dead":
					if (curPoint.y != 3)
					{
						this.bbdc.setFramePointX(0);
						this.bbdc.setFramePointY(3);
					}
					this.bbdc.setState(str);
					return;
				default:
					return;
			}
		}
		
		override protected function scriptFrameOverFunc(row:int):void
		{
			var state:String = this.bbdc.getState();
			switch (state)
			{
				case "walk":
					this.bbdc.setFramePointX(0);
					return;
				case "idle":
					this.bbdc.setFramePointX(0);
					return;
				case "hit1":
					this.setAction("idle");
					return;
				case "hit2":
					this.setAction("idle");
					return;
				case "hurt":
					this.setStatic();
					this.setAction("idle");
					return;
				case "dead":
					this.destroy();
					return;
				default:
					return;
			}
		}
		
		override protected function enterFrameFunc(p:Point):void
		{
			var state:String = this.bbdc.getState();
			var direct:uint = this.getBBDC().getDirect();
			var point:Point = new Point();
			switch (state)
			{
				case "hit1":
					if (p.x == 2)
					{
						if (this.bbdc.getCurFrameCount() == 10)
						{
							if (direct == 0)
							{
								point.x = this.x - 30;
							}
							else
							{
								point.x = this.x + 30;
							}
							point.y = this.y;
							this.doHit1(direct, point);
						}
					}
					return;
				case "hit2":
					if (p.x == 3)
					{
						this.setStatic();
						if (this.bbdc.getCurFrameCount() == 10)
						{
							if (direct == 0)
							{
								point.x = this.x - 30;
							}
							else
							{
								point.x = this.x + 30;
							}
							point.y = this.y;
							this.doHit2(direct, point);
						}
					}
					else if (direct == 0)
					{
						this.velocity.x = -10;
					}
					else
					{
						this.velocity.x = 10;
					}
					return;
				default:
					return;
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			return this.curAttackTarget != null && this.getMp() >= this._petInfo.findPetUsedMagic("sc") && this._petInfo.findHasStudySkill("sc");
		}
		
		override public function reduceHp(re:int, canHurt:Boolean = false):void
		{
			super.reduceHp(re, canHurt);
		}
		
		override protected function releSkill1():void
		{
			this.faceToTarget();
			this.setInvincible(10);
			
			this.setAction("hit2");
			this.lastHit = "hit2";
			_petInfo.reduceMp(this._petInfo.findPetUsedMagic("sc"));
		}
		
		override protected function normalHit():void
		{
			
			this.faceToTarget();
			this.setAction("hit1");
			this.lastHit = "hit1";
		}
		
		override public function getRealPower(param1:String, param2:Boolean = true):int
		{
			var obj:* = null;
			var critValue:uint = this.getCriteValue(param2) ? 2 : 1;
			var hurtAdd:uint = this.getMagicAddValue();
			var wsAdd:Number = this.isGXP ? 1.2 : 1;
			switch (param1)
			{
				case "hit1":
					return (this.getAtk() + hurtAdd) * critValue * wsAdd * this.hurtBaseEffectRate();
				case "hit2":
					obj = this._petInfo.getPetHarmObj("sc");
					if (obj)
					{
						return (obj.first + hurtAdd) * critValue * wsAdd * this.hurtBaseEffectRate();
					}
					return 0;
					break;
				default:
					return 0;
			}
		}
		
		override protected function exitFrameFunc(p:Point):void
		{
		}
		
		override protected function myIntelligence():void
		{
			if (!this.isBeAttacking())
			{
				super.myIntelligence();
			}
		}
		
		override protected function isCannotMoveWhenAttackOnFloor():Boolean
		{
			return this.curAction == "hit1";
		}
		
		override public function isCanMoveWhenAttack():Boolean
		{
			return this.curAction == "hit2";
		}
		
		private function doHit1(direct:uint, point:Point):void
		{
			var b:SpecialEffectBullet = new SpecialEffectBullet("PetMouse1Bullet1");
			if (direct == 0)
			{
				b.x = this.x - 20;
			}
			else
			{
				b.x = this.x + 20;
			}
			b.y = this.y + 10;
			b.setOwner(this);
			b.setDirect(direct);
			b.setAction("hit1");
			gc.gameScene.addChild(b);
			this.magicBulletArray.push(b);
		}
		
		private function doHit2(direct:uint, point:Point):void
		{
			var b:SpecialEffectBullet = new SpecialEffectBullet("PetMouse1Bullet2");
			if (direct == 0)
			{
				b.x = this.x - 40;
			}
			else
			{
				b.x = this.x + 40;
			}
			b.setIsDestroyWhenLastFrame(false);
			b.setDestroyInCount(gc.frameClips * 1);
			b.setFuncWhenHitTarget(this.hit2Hit);
			b.y = this.y + 10;
			b.setOwner(this);
			b.setDirect(direct);
			b.setAction("hit2");
			gc.gameScene.addChild(b);
			this.magicBulletArray.push(b);
		}
		
		private function hit2Hit(bb:BaseBullet):void
		{
			var obj:Object = this._petInfo.getPetHarmObj("sc");
			var hp:int = obj.first + this.getMagicAddValue();
			this.cureHp(hp);
		}
	}
}
